<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty Not_Spam modifier plugin
 *
 * Type:     modifier<br>
 * Name:     not_spam<br>
 * Purpose:  convert email address to Anti Spam link
 * @author   Novachok Alexandr <novachok at ukr dot net>
 * @param string
 * @return string
 */

if(!defined("LIB_REL")) define("LIB_REL", '/lib');

function smarty_modifier_not_spam($string, $alias, $extra)
{
    $string = preg_replace("/(<a\s([^>]*mailto:)((\w|[\-.])+)@((\w|[\-.])+)([^>]*)>)([^>]+<\/a>)/i", "<a href='http://" . $_SERVER['HTTP_HOST'] . LIB_REL . "/not_spam.php?em=$3*cat*$5' " . $extra . " target='mail'>".$alias."</a>", $string);

	$string = preg_replace('/(((\w|[\-.]))+)(\@)((\w|[\-.])+)/i', "<a href='http://" . $_SERVER['HTTP_HOST'] . LIB_REL . "/not_spam.php?em=$1*cat*$5' " . $extra . " target='mail'>".$alias."</a>", $string);

    return $string;
}
?>